<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/views/common/taglibs.jsp" %>
<!DOCTYPE>
<html>
<head>
    <!-- 引入通用js、css文件(xiaogq) -->
    <meta name="decorator" content="bootstrap"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/css/common/operation/sys_operation.css"/>
</head>
<body>
    <!-- 加载列表操作 -->
    <div class="button_list">
        <a href="javascript:;" tableCode="${tableCode}" onclick="recyHandel(1)">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_recoverChosed.png"></span>
                <span name="buTitle">恢复选中</span>
            </span>
        </a>
        <a href="javascript:;" tableCode="${tableCode}" onclick="recyHandel(2)">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_recoverAll.png"></span>
                <span name="buTitle">恢复全部</span>
            </span>
        </a>
        <a href="javascript:;" tableCode="${tableCode}" onclick="recyHandel(3)">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_delChosed.png"></span>
                <span name="buTitle">删除选中</span>
            </span>
        </a>
        <a href="javascript:;" tableCode="${tableCode}" onclick="recyHandel(4)">
            <span class="span_button">
                <span><img src="${ctx}/image/common/operation/oper_delAll.png"></span>
                <span name="buTitle">删除全部</span>
            </span>
        </a>
    </div>
    <!-- 加载bootstrap表格组件div      -->
    <div class="employee_div">
        <table id="bootstrapTable"
               data-striped="true"
               data-toggle="table"
               data-show-columns="true"
               data-cookie="false"
               data-pagination="true"
               data-search="false"
               data-url="${ctx}/Recyclebin/queryRecyclebin.do?tableCode=${tableCode}&fields=${fields}"
               data-side-pagination="server"
               data-checkbox-header="true"
               data-page-list="[10,20,50,1000]"
               class="table">
            <thead>
            <tr>
                ${columns}
            </tr>
            </thead>
        </table>
    </div>
    <script type="text/javascript">
        //数据操作
        function recyHandel(code){
            var selectTip = "", confirmTip = "", items;
            if( code == 1){//如果是恢复选中记录
                selectTip  = "请选择需要恢复的数据！";
                confirmTip = "确认要恢复选中的对象？";
                items = $('#bootstrapTable').bootstrapTable('getSelections');
            }else if ( code == 2 ){//如果是恢全部记录
                selectTip = "请选择需要恢复的数据！";
                confirmTip  = "确定恢复当前列表的对象？";
                items = $('#bootstrapTable').bootstrapTable('getData');
            }else if ( code == 3 ){//如果是删除选中记录
                selectTip  = "请选择需要删除的数据！";
                confirmTip = "确认要删除选中的对象？";
                items = $('#bootstrapTable').bootstrapTable('getSelections');
            }else{//如果是删除全部记录
                selectTip = "请选择需要删除的数据！";
                confirmTip  = "确定删除当前列表的对象？";
                items = $('#bootstrapTable').bootstrapTable('getData');
            }
            if( items.length == 0 ){
                alert(selectTip);
                return false;
            }
            var itemlist = [];
            for(i = 0; i < items.length; i++){
                itemlist.push( items[i].id );
            }
            //console.log("itemlist==",itemlist);
            if(itemlist.length > 0){
                if(confirm(confirmTip)){
                    $.ajax({
                        type: "POST",
                        url: "${ctx}/Recyclebin/recyclebinHandel.do?entity_id=${tableCode}&code="+code+"&records="+itemlist,
                        success : function(data){
                            var flag = data.flag;
                            if(!flag){
                                alert("恢复或删除数据失败!");
                            }
                            $("#bootstrapTable").bootstrapTable("refresh");
                        },
                        error: function(data){
                            alert("恢复或删除数据发生错误!");
                        }
                    });
                }
            }else{
                $("#bootstrapTable").bootstrapTable("refresh");
            }
        }
    </script>
</body>
</html>
